import React, { Component } from 'react';
import { Table, Message, Pagination } from '@alifd/next';
import IceContainer from '@icedesign/container';
import eventProxy from '../../../../../libs/eventProxy';
import { page, update, del } from '../../../../../api/Log';
import DeleteBalloon from '../../../../../libs/DeleteBalloon';
import EditDialog from '../EditDialog';
import '../../LogTable.scss';

export default class TreeTable extends Component {
  static displayName = 'TreeTable';

  static propTypes = {
  };
   myprops={};
  static defaultProps = {};
  constructor(props) {
    super(props);
    this.state = {
      sourceData: [],
      offset: 0,
      limit: 10,
      total: 10,
    };
    this.onChangePage = this.onChangePage.bind(this);
  }

  componentDidMount() {
    this.updateTable(this.state.offset, this.state.limit);
  }
  updateTable(offset, limit) {
    page({
      offset: offset,
      limit: limit,
    }).then((response) => {
      const data = response.data.data;
      this.setState({
        sourceData: data.rows,
        refresh: false,
        total: data.count,
      });
    });
  }
  
  onChangePage = (cur) => {
    const offset = (cur - 1) * this.state.limit;
    this.updateTable(offset, this.state.limit);
    this.setState({
      offset: offset, 
    });
  }

  render() {
    const isZebra = true;
    const rendType = (value) => {
      return (<span>{value == '1' ? '访问日志' : '异常日志'}</span>);
    };
    return (
      <IceContainer>
        <Table
          dataSource={this.state.sourceData}
          primaryKey="id"
          isZebra={isZebra}
          align="center"
          rowSelection={{ onChange: () => {} }}
        >
          <Table.Column title="访问系统" dataIndex="appId" />
          <Table.Column title="登录名" dataIndex="createBy" />
          <Table.Column title="日志类型" dataIndex="type" cell={rendType} />
          <Table.Column title="访问ip" dataIndex="remoteAddr" />
          <Table.Column title="请求接口" dataIndex="requestUri" />
          <Table.Column title="访问时间" dataIndex="createDate" />
        </Table>
        <Pagination onChange={this.onChangePage} pageSize={this.state.limit} total={this.state.total} className="paging" />
      </IceContainer>
    );
  }
}
